package br.liveo.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;
import android.widget.ImageView;

public class Utils {
	public static Bitmap loadBitmapFromView(View mView) {
		Bitmap b = Bitmap.createBitmap(mView.getWidth(), mView.getHeight(),
				Bitmap.Config.ARGB_8888);

		Canvas c = new Canvas(b);

		mView.draw(c);

		return b;
	}

	public static Bitmap scaleBitmap(Bitmap myBitmap, float mDownScaleFactor) {

		int width = (int) (myBitmap.getWidth() / mDownScaleFactor);
		int height = (int) (myBitmap.getHeight() / mDownScaleFactor);

		return Bitmap.createScaledBitmap(myBitmap, width, height, false);
	}

	public static void blurBitmap(Context context, View v, int radius,
			int factor) {
		Bitmap bmp = loadBitmapFromView(v);
		bmp = scaleBitmap(bmp, factor);
		((ImageView) v).setImageBitmap(Blur.fastblur(context, bmp, radius,
				false));
	}
}
